<template>
	<view :style='{"padding-top": (statusBarHeight + 70)+"px"}'>
		<view class="fixed-top" :style='{"padding-top": statusBarHeight+"px"}'>
			<view class="acea-row row-middle row-between search-header">
				<!-- <image src="" mode="aspectFill" @click="goback"></image> -->
				<view class="iconfont icon-xiangzuo on" @click="goback"></view>
				<view class="acea-row row-middle search-box" style="margin-left: 20rpx;">
					<view class="search-ipt">
						<text class="iconfont icon-xiazai5"></text>
						<input class="uni-input" placeholder="搜索" v-model="searchKey" @confirm="toSearch" />
					</view>
				</view>
			</view>
		</view>
		<view class="list">
			<view class="item" v-for="item in propertysData" :key="item.id">
				<view class="acea-row row-middle name border-b">
					<!-- <image src="../static/images/property_01.png" mode=""></image> -->
					<view>{{item.projectName?item.projectName:''}}</view>
				</view>
				<view class="info-box border-b">
					<!-- 		<view class="reg-tag">
						未审核
					</view> -->
					<view class="acea-row row-middle info">
						<view class="label">地址</view>
						<view class="text">{{item.address}}</view>
					</view>
					<view class="acea-row row-middle info">
						<view class="label">物业类型</view>
						<view class="text">{{item.valueName}}</view>
					</view>
					<view class="acea-row row-middle info">
						<view class="label">产权面积</view>
						<view class="text">{{item.floorage}}㎡楼层 </view>
					</view>
					<view class="acea-row row-middle info">
						<view class="label">楼层</view>
						<view class="text">{{item.floor}}层 </view>
					</view>
					<view class="acea-row row-middle info">
						<view class="label">户型</view>
						<view class="text">{{item.houserName?item.houserName:''}}</view>
					</view>
					<view class="acea-row row-middle info">
						<view class="label">装修</view>
						<view class="text">{{item.renovation == '0'? '否':'是'}}</view>
					</view>
					<view class="acea-row row-middle info">
						<view class="label">房产认证</view>
						<view class="text">{{(item.houser&&Object.keys(item.houser).length>0?'已认证':'未认证')}}</view>
					</view>
				</view>
				<view class="acea-row row-middle row-right btns">
					<view class="btn" @click="toPer(item.id,'出租',item.valueName)">出租</view>
					<view class="btn" @click="toPer(item.id,'出售',item.valueName)">出售</view>
					<view class="btn" @click="toEdit(item.id)">编辑</view>
					<view class="btn" @click="toDelete(item.id)">删除</view>
				</view>
			</view>
		</view>
		<view class='loadingicon acea-row row-center row-middle'>
			<text class='loading iconfont icon-jiazai' :hidden='loading'></text>{{loadTitle}}
		</view>
		<view class="uni-p-b-98"></view>
		<view class="add-btn" @click="toAdd">新增物业信息</view>
	</view>
</template>

<script>
	import {
		getOnList,
		delProperty
	} from '@/api/centerModule/index.js';
	var app = getApp();
	export default {
		data() {
			return {
				limit: 3,
				page: 1,
				propertysData: [],
				loading: true,
				statusBarHeight: 0,
				loadTitle: '',
				searchKey: '',
				types: [{
					name: '出租'
				}, {
					name: '转让'
				}, {
					name: '求租'
				}, {
					name: '出售'
				}, {
					name: '求购'
				}],
				categoryList: [{
					name: '商铺',
				}, {
					name: '写字楼',
				}, {
					name: '公寓',
				}, {
					name: '厂房',
				}, {
					name: '仓库',
				}, {
					name: '土地',
				}, {
					name: '房屋',
				}],
			};
		},
		onLoad() {
			// #ifdef MP || APP-PLUS
			let height = app.globalData.navHeight2;
			this.statusBarHeight = height;
			// #endif
			// #ifdef H5
			this.statusBarHeight = 60;
			// #endif
		},
		methods: {
			goback() {
				// #ifdef H5
				return history.back();
				// #endif
				// #ifndef H5
				return uni.navigateBack({
					delta: 1,
				})
				// #endif
			},
			toAdd() {
				let that = this;
				uni.navigateTo({
					url: '/pages/releases/propertys/propertys',
					events: {
						upList: function() {
							that.getOnListData();
						}
					}
				})
			},
			getOnListData() {
				this.loading = false;
				getOnList({
					limit: this.limit,
					page: this.page,
					title: this.searchKey
				}).then(res => {
					this.loading = true;
					if (this.page == 1) {
						this.propertysData = res.data.list;
						if (this.propertysData.length <= 0) {
							this.loadTitle = '暂无数据'
						}
					} else {
						this.propertysData = this.propertysData.concat(res.data.list);
						if (res.data.list.length <= 0) {
							this.loadTitle = '已加载所有'
						}
					}

				})
			},
			toPer(id, tname, cname) {
				let typeOn = '';
				let categoryOn = '';
				this.types.forEach((item, index) => {
					if (item.name == tname) {
						typeOn = index;
					}
				})
				this.categoryList.forEach((item, index) => {
					if (item.name == cname.trim()) {
						categoryOn = index;
					}
				})
				uni.navigateTo({
					url: "/pages/releases/subletOfShop/subletOfShop?typeOn=" + typeOn + '&categoryOn=' +
						categoryOn + '&patientinfoId=' + id
				})
			},
			toEdit(id) {
				let that = this;
				uni.navigateTo({
					url: '/pages/releases/propertys/propertys?id=' + id,
					events: {
						upList: function() {
							that.page = 1;
							that.getOnListData();
						}
					}
				})
			},
			toSearch() {
				this.page = 1;
				this.getOnListData();

			},
			toDelete(id) {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '你确定要删除吗',
					success: function(res) {
						if (res.confirm) {
							delProperty(id).then(res => {
								that.page = 1;
								that.getOnListData();
							})
						} else if (res.cancel) {
							console.log('取消');
						}
					}
				});
			}
		},
		created() {
			this.getOnListData()
		},
		onReachBottom() {
			this.page++;
			this.getOnListData();
		}

	}
</script>

<style lang="scss">
	.list {
		padding: 30rpx;
	}

	.border-b {
		border-bottom: 1px solid rgba(238, 238, 238, 1);
	}
	.fixed-top {
		width: 100%;
		background: #EE212D;
		position: fixed;
		top: 0;
		left: 0;
		height: 122rpx;
		z-index: 999;
		background: linear-gradient(90deg, #EE212D 0%, #EE212D 100%);
	}
	.icon-xiangzuo {
		color: #ffffff;
		// position: absolute;
		font-size: 40rpx;
		// left: 0rpx;
		// width: 100rpx;
		// height: 56rpx;
		// line-height: 54rpx;
		// top: 50%;
		// transform: translateY(-50%);
	}

	.item {
		border-radius: 10rpx;
		margin-bottom: 24rpx;
		padding: 0 30rpx;
		background: #fff;

		.name {
			font-size: 28rpx;
			font-weight: 400;
			line-height: 42rpx;
			color: rgba(56, 56, 56, 1);
			padding: 30rpx 30rpx 30rpx 0;
			position: relative;

			&::before {
				position: absolute;
				right: 0;
				top: 50%;
				transform: translateY(-50%);
				content: '';
				display: block;
				border-top: 1px solid rgba(196, 196, 196, 1);
				border-right: 1px solid rgba(196, 196, 196, 1);
				transform: rotate(45deg);
				width: 14rpx;
				height: 14rpx;
			}

			image {
				width: 44rpx;
				height: 44rpx;
				margin-right: 6rpx;
			}
		}
	}

	.info-box {
		padding: 30rpx 0;
		position: relative;

		.red-tag {
			position: absolute;
			right: 0;
			top: 30rpx;
			font-size: 24rpx;
			font-weight: 400;
			color: rgba(238, 33, 45, 1);
		}

		.info {
			width: 90%;
			font-size: 26rpx;
			font-weight: 400;
			line-height: 50rpx;
			color: rgba(128, 128, 128, 1);

			.label {
				width: 140rpx;

			}
		}
	}

	.btns {
		padding: 30rpx 0;

		.btn {
			margin-left: 24rpx;
			padding: 4rpx 24rpx;
			border-radius: 6rpx;
			border: 1px solid rgba(229, 229, 229, 1);
			background: #fff;
			font-size: 24rpx;
			font-weight: 400;
			line-height: 40rpx;
			color: rgba(128, 128, 128, 1);
		}
	}

	.add-btn {
		width: 400rpx;
		height: 98rpx;
		opacity: 1;
		border-radius: 50rpx;
		background: rgba(238, 33, 45, 1);
		box-shadow: 0px 3px 8px 0px rgba(245, 15, 30, 0.2);
		position: fixed;
		bottom: 60rpx;
		left: 50%;
		transform: translateX(-50%);
		font-size: 36rpx;
		font-weight: 400;
		line-height: 98rpx;
		color: rgba(255, 250, 250, 1);
		text-align: center;
	}

	.fixed-top {
		width: 100%;
		background: #EE212D;
		height: 122rpx;
		z-index: 999;
		background: linear-gradient(90deg, #EE212D 0%, #EE212D 100%);
	}

	.search-header {
		width: 100%;
		padding: 26rpx;
		background: #EE212D;

		image {
			width: 28rpx;
			height: 32rpx;
			margin-right: 34rpx;
		}

		.search-map {
			font-size: 22rpx;
			font-weight: 400;
			color: rgba(255, 255, 255, 1);
			text-align: center;

			image {
				width: 40rpx;
				height: 36rpx;
			}
		}
	}

	.search-box {
		// width: 586rpx;
		flex: 1;
		height: 70rpx;
		opacity: 1;
		border-radius: 36rpx;
		background: rgba(255, 255, 255, 1);
		padding: 12rpx 32rpx;

		.search-ipt {
			display: flex;
			align-items: center;
			color: rgba(166, 166, 166, 1);

			text {
				padding: 0 16rpx 0 0rpx;
			}
		}
	}
</style>